package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_cash_rounding;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_cash_roundingSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_cash_roundingService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[帐户现金舍入] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_cash_roundingServiceImpl implements IAccount_cash_roundingService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_cash_roundingClientService account_cash_roundingClientService;

    @Override
    public boolean create(Account_cash_rounding account_cash_rounding) {
        boolean bOk = false ;
        Iaccount_cash_rounding clientModel = this.convert2Model(account_cash_rounding,null);
        account_cash_roundingClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_cash_rounding);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Account_cash_rounding get(Integer id) {
        Iaccount_cash_rounding clientModel = account_cash_roundingClientService.createModel();
        clientModel.setId(id);
        account_cash_roundingClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_cash_rounding get(Account_cash_rounding account_cash_rounding) {
        Account_cash_rounding retaccount_cash_rounding = this.get(account_cash_rounding.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_cash_rounding.getClass(), account_cash_rounding.getClass(), false);
        copier.copy(retaccount_cash_rounding, account_cash_rounding, null);
        return account_cash_rounding ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_cash_rounding clientModel = account_cash_roundingClientService.createModel();
        clientModel.setId(id);
        account_cash_roundingClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_cash_roundingClientService.removeBatch(account_cash_roundings) ;

    }

    @Override
    public void createBatch(List<Account_cash_rounding> account_cash_roundings, int batchSize) {

                        //account_cash_roundingClientService.createBatch(account_cash_roundings,batchSize) ;

    }

    @Override
    public boolean update(Account_cash_rounding account_cash_rounding) {
        boolean bOk = false ;
        Iaccount_cash_rounding clientModel = this.convert2Model(account_cash_rounding,null);
        account_cash_roundingClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_cash_rounding) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Account_cash_rounding> account_cash_roundings, int batchSize) {

        //account_cash_roundingClientService.updateBatch(account_cash_roundings,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_cash_rounding> searchDefault(Account_cash_roundingSearchContext context) {
        List<Account_cash_rounding> list = new ArrayList<Account_cash_rounding>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding> clientModelList = account_cash_roundingClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_cash_rounding>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据科目查询
     */
    @Override
    public Page<Account_cash_rounding> selectByOdoo_account(Integer id){
        Account_cash_roundingSearchContext context = new Account_cash_roundingSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_cash_rounding> list = new ArrayList<Account_cash_rounding>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding> clientModelList = account_cash_roundingClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_cash_rounding>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_cash_rounding> selectByOdoo_create(Integer id){
        Account_cash_roundingSearchContext context = new Account_cash_roundingSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_cash_rounding> list = new ArrayList<Account_cash_rounding>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding> clientModelList = account_cash_roundingClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_cash_rounding>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_cash_rounding> selectByOdoo_write(Integer id){
        Account_cash_roundingSearchContext context = new Account_cash_roundingSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_cash_rounding> list = new ArrayList<Account_cash_rounding>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding> clientModelList = account_cash_roundingClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_cash_rounding clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_cash_rounding>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_cash_rounding convert2Model(Account_cash_rounding domain , Iaccount_cash_rounding model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_cash_roundingClientService.createModel() ;
        }

         if(domain.getRounding_methodDirtyFlag())
            model.setRounding_method(domain.getRounding_method());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getStrategyDirtyFlag())
            model.setStrategy(domain.getStrategy());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getRoundingDirtyFlag())
            model.setRounding(domain.getRounding());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getAccount_id_textDirtyFlag())
            model.setAccount_id_text(domain.getAccount_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getAccount_idDirtyFlag())
            model.setAccount_id(domain.getAccount_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Account_cash_rounding convert2Domain( Iaccount_cash_rounding model ,Account_cash_rounding domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_cash_rounding();
        }

        if(model.getRounding_methodDirtyFlag())
            domain.setRounding_method(model.getRounding_method());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getStrategyDirtyFlag())
            domain.setStrategy(model.getStrategy());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getRoundingDirtyFlag())
            domain.setRounding(model.getRounding());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getAccount_id_textDirtyFlag())
            domain.setAccount_id_text(model.getAccount_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getAccount_idDirtyFlag())
            domain.setAccount_id(model.getAccount_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
